//
//  QZShowCatagaryCell.m
//  WeiWeiHaircut
//
//  Created by 超群 on 15/10/15.
//  Copyright © 2015年 超群. All rights reserved.
//

#import "QZShowCatagaryCell.h"
#import "MyButton.h"
#import "QZShopListController.h"
#import "QZShopCategory.h"

@implementation QZShowCatagaryCell{
    
    UIView *_backView;
}



-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setSelectionStyle:UITableViewCellSelectionStyleNone];
//
        
        
        
    }
    return self;
    
}

-(void)addCategoryImage{
    CGFloat gay = 35;
    CGFloat buttonW = (SCREEN_W-4*gay)/3;
    CGFloat buttonH =buttonW;
    
    
    
    UIView *bgview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W,((_categarys.count-1)/3+1)*(buttonH + gay)+gay)];
    [self.contentView addSubview:bgview];
    _backView = bgview;
    UIImageView *view = [[UIImageView alloc] initWithFrame:CGRectMake(10, 15, 5, 10)];
    view.backgroundColor = [UIColor colorWithRed:180/255.0 green:90/255.0 blue:234/255.0 alpha:1];;
    [bgview addSubview:view];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view.frame)+10, 6, 100, 30)];
    label.textColor = [UIColor colorWithRed:180/255.0 green:90/255.0 blue:234/255.0 alpha:1];//180,90,234
    label.text = @"热门活动";
    [bgview addSubview:label];
    
    
//    NSArray *titles = @[@"洗发",@"护发",@"染发",@"剪发",@"熨烫",@"会员"];

    for (int i = 0; i<_categarys.count; i ++ ) {
        NSLog(@"%d",i);
        
        MyButton *button = [MyButton buttonWithType:UIButtonTypeCustom frame:CGRectMake(gay+i%3*(gay+buttonW), gay+i/3*(buttonH+gay), buttonW, buttonH) title:@"染发" bgImage:@"染发" image:nil selectedImage:nil block:^{
            
            QZShopCategory *model = _categarys[i];
            //点击事件
            if (_catagaryBlock) {
                _catagaryBlock(model);
            }
        }];
 
        
        [bgview addSubview:button];
    }
    
    
    
}


- (void)awakeFromNib {
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


-(void)setCategarys:(NSArray *)categarys{
    _categarys = categarys;

    int index=0;
    
    if (!_backView) {
        [self addCategoryImage];
    }
    
    
    for (int i = 0; i<_backView.subviews.count; i++) {
        if ([_backView.subviews[i] isKindOfClass:[UIButton class]]) {
            
            UIButton *button = _backView.subviews[i];
            
            QZShopCategory *model = categarys[index];
            
            //这个图片是根据categarys 里面的Model imageURL;
            [button setBackgroundImage:[UIImage imageNamed:@"洗发"] forState:UIControlStateNormal];
            
            [button setTitle:model.proName forState:UIControlStateNormal];
            index ++ ;
        }
    }
    
    
    
}
@end
